Locality grouping during garbage collection of a storage device

ABSTRACT

Systems, methods and/or devices are used to enable locality grouping during garbage collection of a storage device. In one aspect, the method includes, at a storage controller for the storage device: performing one or more operations for a garbage collection read, including: identifying one or more sequences of valid data in a source unit, wherein each identified sequence of valid data has a length selected from a set of predefined lengths; and for each respective sequence of the one or more sequences of valid data in the source unit, transferring the respective sequence to a respective queue of a plurality of queues, in accordance with the length of the respective sequence; and performing one or more operations for a garbage collection write, including: identifying full respective queues for writing to a destination unit; and writing from the full respective queues to the destination unit.

RELATED APPLICATIONS

This application claims priority to U.S. Provisional Patent ApplicationNo. 62/508,326, filed May 18, 2017, which is hereby incorporated byreference in its entirety. This application is also related to U.S.Provisional Patent Application No. 62/508,236, filed May 18, 2017, whichis hereby incorporated by reference in its entirety.

TECHNICAL FIELD

The disclosed embodiments relate generally to memory systems, and inparticular, to locality grouping during garbage collection of a storagedevice (e.g., comprising one or more flash memory devices).

BACKGROUND

Semiconductor memory devices, including flash memory, typically utilizememory cells to store data as an electrical value, such as an electricalcharge or voltage. A flash memory cell, for example, includes a singletransistor with a floating gate that is used to store a chargerepresentative of a data value. Flash memory is a non-volatile datastorage device that can be electrically erased and reprogrammed. Moregenerally, non-volatile memory (e.g., flash memory, as well as othertypes of non-volatile memory implemented using any of a variety oftechnologies) retains stored information even when not powered, asopposed to volatile memory, which requires power to maintain the storedinformation. Increases in storage density have been facilitated invarious ways, including increasing the density of memory cells on a chipenabled by manufacturing developments, and transitioning fromsingle-level flash memory cells to multi-level flash memory cells, sothat two or more bits can be stored by each flash memory cell.

Garbage collection is a process of memory management that reclaimsportions of memory that no longer contain valid data. Using flash memoryas an example, data is written to flash memory in units called pages,which are made up of multiple memory cells. However, flash memory iserased in larger units called blocks, which are made up of multiplepages. If some pages of a first block contain invalid data, those pagescannot be overwritten until the whole block containing those pages iserased. The process of garbage collection reads and re-writes the pageswith valid data from the first block into a second block and then erasesthe first block. After garbage collection, the second block containspages with valid data and free pages that are available for new data tobe written. However, blindly gathering valid data in a source block(e.g., the first block) and re-writing the valid data to a destinationblock (e.g., the second block) can degrade the performance of host readoperations after garbage collection.

SUMMARY

Various embodiments of systems, methods and devices within the scope ofthe appended claims each have several aspects, no single one of which issolely responsible for the attributes described herein. Without limitingthe scope of the appended claims, after considering this disclosure, andparticularly after considering the section entitled “DetailedDescription” one will understand how the aspects of various embodimentsare used to enable locality grouping during garbage collection of astorage device. In one aspect, one or more operations for a garbagecollection read is performed, including identifying one or moresequences of valid data in a source unit, wherein each identifiedsequence of valid data has a length selected from a set of predefinedlengths, and for each respective sequence of the one or more sequencesof valid data in the source unit, transferring the respective sequenceto a respective queue, in accordance with the length of the respectivesequence; and one or more operations for a garbage collection write isperformed, including identifying respective queues for writing to adestination unit, and writing from the respective queues to thedestination unit.

BRIEF DESCRIPTION OF THE DRAWINGS

So that the present disclosure can be understood in greater detail, amore particular description may be had by reference to the features ofvarious embodiments, some of which are illustrated in the appendeddrawings. The appended drawings, however, merely illustrate pertinentfeatures of the present disclosure and are therefore not to beconsidered limiting, for the description may admit to other effectivefeatures.

FIG. 1 is a block diagram illustrating an implementation of a datastorage system, in accordance with some embodiments.

FIG. 2 is a block diagram illustrating an implementation of a managementmodule, in accordance with some embodiments.

FIG. 3 illustrates a conventional implementation of garbage collection.

FIGS. 4A-4B illustrate locality grouping during garbage collection, inaccordance with some embodiments.

FIG. 5 illustrates various patterns used to detect sequences of validdata, in accordance with some embodiments.

FIGS. 6A-6C illustrate garbage collection writes with incomplete queues,in accordance with some embodiments.

FIGS. 7A-7B illustrate locality grouping during garbage collection withmultiple memory channels, in accordance with some embodiments.

FIGS. 8A-8E illustrate a flowchart representation of a method ofoperating a storage device, in accordance with some embodiments.

FIGS. 9A-9D illustrate a flowchart representation of a method ofoperating a storage device, in accordance with some embodiments.

In accordance with common practice the various features illustrated inthe drawings may not be drawn to scale. Accordingly, the dimensions ofthe various features may be arbitrarily expanded or reduced for clarity.In addition, some of the drawings may not depict all of the componentsof a given system, method or device. Finally, like reference numeralsmay be used to denote like features throughout the specification andfigures.

DETAILED DESCRIPTION

The various embodiments described herein include systems, methods and/ordevices used to enable locality grouping during garbage collection of astorage device. Some embodiments include systems, methods and/or devicesto perform one or more operations for a garbage collection read,including identifying sequences of valid data in a source unit, whereineach identified sequence of valid data has a length selected from a setof predefined lengths, and for each respective sequence of the sequencesof valid data in the source unit, transferring the respective sequenceto a respective queue, in accordance with the length of the respectivesequence; and perform one or more operations for a garbage collectionwrite, including identifying full respective queues for writing to adestination unit, and writing from the full respective queues to thedestination unit.

(A1) More specifically, some embodiments include a method for operatinga storage device that includes non-volatile memory. In some embodiments,the method includes, at a storage controller for the storage device:receiving a plurality of garbage collection requests, wherein eachgarbage collection request specifies a source unit; in response toreceiving a garbage collection request of the plurality of garbagecollection requests, performing one or more operations for a garbagecollection read, including: identifying one or more sequences of validdata in the source unit, wherein each identified sequence of valid datahas a length selected from a set of predefined lengths, the setincluding a first length, a second length, and a third length; and foreach respective sequence of the one or more sequences of valid data inthe source unit, transferring the respective sequence to a respectivequeue of a plurality of queues, in accordance with the length of therespective sequence; and after performing the one or more operations forthe garbage collection read, performing one or more operations for agarbage collection write, including: identifying full respective queuesfor writing to a destination unit; and writing from the full respectivequeues to the destination unit.

(A2) In some embodiments of the method of A1, the plurality of queuescomprises buffer memory distinct from non-volatile memory in thedestination unit.

(A3) In some embodiments of the method of any of A1 to A2, the storagecontroller for the storage device includes a first module and a secondmodule; receiving the plurality of garbage collection requests includesreceiving, at the second module, a plurality of garbage collection readrequests from the first module; and the one or more operations for thegarbage collection read are performed in response to receiving arespective garbage collection read request of the plurality of garbagecollection read requests.

(A4) In some embodiments of the method of A3, the method furtherincludes: prior to performing one or more operations for the garbagecollection write, receiving, at the second module, a garbage collectionwrite request from the first module; and performing the one or moreoperations for the garbage collection write in response to receiving thegarbage collection write request.

(A5) In some embodiments of the method of any of A1 to A4, wherein eachsequence of the one or more sequences of valid data in the source unitincludes one or more logical pages of valid data.

(A6) In some embodiments of the method of any of A1 to A5, identifyingthe one or more sequences of valid data in the source unit includes: foreach respective sequence of valid data, determining whether therespective sequence has the first length, the second length, or thethird length by: determining whether the respective sequence has thethird length; in accordance with a determination that the respectivesequence does not have the third length, determining whether therespective sequence has the second length; and in accordance with adetermination that the respective sequence does not have the secondlength, determining whether the respective sequence has the firstlength.

(A7) In some embodiments of the method of any of A1 to A6, transferringthe respective sequence to the respective queue of the plurality ofqueues, in accordance with the length of the respective sequence,includes: in accordance with a determination that the respectivesequence of valid data has the first length, transferring the respectivesequence of valid data into a first queue of a first type; in accordancewith a determination that the respective sequence of valid data has thesecond length, transferring the respective sequence of valid data into asecond queue of a second type; and in accordance with a determinationthat the respective sequence of valid data has the third length,transferring the respective sequence of valid data into a third queue ofa third type.

(A8) In some embodiments of the method of A7, the first queue, thesecond queue, and the third queue are the same size.

(A9) In some embodiments of the method of any of A7 to A8, in theplurality of queues, queues of the first type of queue each hold singlelogical pages.

(A10) In some embodiments of the method of any of A7 to A9, in theplurality of queues, queues of the second type of queue each hold atleast one sequence of logical pages of at least the second length.

(A11) In some embodiments of the method of any of A7 to A10, in theplurality of queues, queues of the third type of queue each hold atleast one sequence of logical pages of at least the third length.

(A12) In some embodiments of the method of any of A7 to A11, the methodfurther includes: in accordance with a determination that the firstqueue of the first type is full, allocating a fourth queue of the firsttype; in accordance with a determination that the second queue of thesecond type is full, allocating a fifth queue of the second type; and inaccordance with a determination that the third queue of the third typeis full, allocating a sixth queue of the third type.

(A13) In some embodiments of the method of any of A1 to A12, writingfrom the full respective queues to the destination unit includes writingfrom the full respective queues in sequence, from an oldest fullrespective queue to a newest full respective queue, to the destinationunit.

(A14) In some embodiments of the method of any of A1 to A13, writingfrom the full respective queues to the destination unit includes writingfrom the full respective queues to the destination unit until thedestination unit is full.

(A15) In some embodiments of the method of any of A1 to A14, the methodfurther includes: prior to performing the one or more operations for thegarbage collection write: in accordance with logical addressinformation, rearranging one or more sequences of valid data in theplurality of queues to group logically sequential data together, whereinat least one queue in the plurality of queues has a longer sequence oflogically sequential data after the rearranging than before therearranging.

(A16) In some embodiments of the method of any of A1 to A15, identifyingfull respective queues and writing from the full respective queuesincludes: identifying full respective queues for writing to one or moredestination units in one or more memory channels, respectively; and inaccordance with a determination that at least N of the full respectivequeues are logically sequential, where N is a predefined integer greaterthan one, writing the N full respective queues that are logicallysequential to destination units in at least two different memorychannels.

(A17) In some embodiments of the method of A16, writing the N fullrespective queues that are logically sequential to destination units inat least two different memory channels includes: writing from a firstqueue of the N full respective queues that are logically sequential to afirst destination unit of a first memory channel; and writing from asecond queue of the N full respective queues that are logicallysequential to a second destination unit of a second memory channel.

(A18) In some embodiments of the method of any of A1 to A17, the storagedevice comprises one or more flash memory devices.

(A19) In another aspect, a storage device includes (1) non-volatilememory (e.g., comprising one or more non-volatile storage devices, suchas flash memory devices), (2) one or more processors, and (3) controllermemory (e.g., non-volatile memory or volatile memory in or coupled tothe controller) storing one or more programs, which when executed by theone or more processors cause the storage device to perform or controlperformance of any of the methods A1 to A18 described herein.

(A21) In yet another aspect, any of the methods A1 to A18 describedabove are performed by a storage device including means for performingany of the methods described herein.

(A23) In yet another aspect, a storage system includes (1) a storagemedium (e.g., comprising one or more non-volatile storage devices, suchas flash memory devices) (2) one or more processors, and (3) memory(e.g., non-volatile memory or volatile memory in the storage system)storing one or more programs, which when executed by the one or moreprocessors cause the storage system to perform or control performance ofany of the methods A1 to A18 described herein.

(A24) In yet another aspect, some embodiments include a non-transitorycomputer readable storage medium, storing one or more programsconfigured for execution by one or more processors of a storage device,the one or more programs including instructions for performing any ofthe methods A1 to A18 described herein.

The various embodiments described herein include systems, methods and/ordevices used to enable locality grouping during garbage collection of astorage device. Some embodiments include systems, methods and/or devicesto perform one or more operations for a garbage collection read,including: identifying sequences of valid data in a source unit, whereineach identified sequence of valid data has a length selected from a setof predefined lengths; for each respective sequence of the sequences ofvalid data in the source unit, transferring the respective sequence to arespective queue, in accordance with the length of the respectivesequence; and setting a global flag to flush all open queues; andperform one or more operations for a garbage collection write, includingidentifying open respective queues for writing to a destination unit,and writing from the open respective queues to the destination unit.

(B1) More specifically, some embodiments include a method for operatinga storage device that includes non-volatile memory. In some embodiments,the method includes, at a storage controller for the storage device, thestorage controller including a first module and a second module:receiving, at the second module, a garbage collection read request fromthe first module, wherein the garbage collection read request specifiesa source unit and a tag to indicate the source unit contains last validpages in a block; in response to receiving the garbage collection readrequest, performing one or more operations for a garbage collectionread, including: identifying one or more sequences of valid data in thesource unit, wherein each identified sequence of valid data has a lengthselected from a set of predefined lengths, the set including a firstlength, a second length, and a third length; for each respectivesequence of the one or more sequences of valid data in the source unit,transferring the respective sequence to a respective queue of aplurality of queues, in accordance with the length of the respectivesequence; and setting a global flag to flush all open respective queues;receiving, at the second module, a garbage collection write request fromthe first module; and in response to receiving the garbage collectionwrite request and in accordance with the global flag, performing one ormore operations for a garbage collection write, including: identifyingopen respective queues for writing to a destination unit, wherein openrespective queues contain one or more sequences of valid data; andwriting from the open respective queues to the destination unit.

(B2) In some embodiments of the method of B1, at least one of theidentified open respective queues is not full.

(B3) In some embodiments of the method of B2, writing from the openrespective queues to the destination unit includes combining openrespective queues that are not full to minimize unused space in thedestination unit.

(B4) In some embodiments of the method of any of B1 to B3, the pluralityof queues comprises buffer memory distinct from non-volatile memory inthe destination unit.

(B5) In some embodiments of the method of any of B1 to B4, each sequenceof the one or more sequences of valid data in the source unit includesone or more logical pages of valid data.

(B6) In some embodiments of the method of any of B1 to B5, identifyingthe one or more sequences of valid data in the source unit includes: foreach respective sequence of valid data, determining whether therespective sequence has the first length, the second length, or thethird length by: determining whether the respective sequence has thethird length; in accordance with a determination that the respectivesequence does not have the third length, determining whether therespective sequence has the second length; and in accordance with adetermination that the respective sequence does not have the secondlength, determining whether the respective sequence has the firstlength.

(B7) In some embodiments of the method of any of B1 to B6, transferringthe respective sequence to the respective queue of the plurality ofqueues, in accordance with the length of the respective sequence,includes: in accordance with a determination that the respectivesequence of valid data has the first length, transferring the respectivesequence of valid data into a first queue of a first type; in accordancewith a determination that the respective sequence of valid data has thesecond length, transferring the respective sequence of valid data into asecond queue of a second type; and in accordance with a determinationthat the respective sequence of valid data has the third length,transferring the respective sequence of valid data into a third queue ofa third type.

(B8) In some embodiments of the method of B7, the first queue, thesecond queue, and the third queue are the same size.

(B9) In some embodiments of the method of any of B7 to B8, in theplurality of queues, queues of the first type of queue each hold singlelogical pages.

(B10) In some embodiments of the method of any of B7 to B9, in theplurality of queues, queues of the second type of queue each hold atleast one sequence of logical pages of at least the second length.

(B11) In some embodiments of the method of any of B7 to B10, in theplurality of queues, queues of the third type of queue each hold atleast one sequence of logical pages of at least the third length.

(B12) In some embodiments of the method of any of B7 to B11, the methodfurther includes: in accordance with a determination that the firstqueue of the first type is full, allocating a fourth queue of the firsttype; in accordance with a determination that the second queue of thesecond type is full, allocating a fifth queue of the second type; and inaccordance with a determination that the third queue of the third typeis full, allocating a sixth queue of the third type.

(B13) In some embodiments of the method of any of B1 to B12, writingfrom the open respective queues to the destination unit includes writingfrom the open respective queues in sequence, from oldest open respectivequeue to newest open respective queue, to the destination unit.

(B14) In some embodiments of the method of any of B1 to B13, the methodfurther includes: after writing from the open respective queues to thedestination unit, marking the block as eligible for erasing.

(B15) In some embodiments of the method of any of B1 to B14, the storagedevice comprises one or more flash memory devices.

(B16) In another aspect, a storage device includes (1) non-volatilememory (e.g., comprising one or more non-volatile storage devices, suchas flash memory devices), (2) a storage controller for the storagedevice, the storage controller including a first module and a secondmodule, (3) one or more processors, and (4) controller memory (e.g.,non-volatile memory or volatile memory in or coupled to the controller)storing one or more programs, which when executed by the one or moreprocessors cause the storage device to perform or control performance ofany of the methods B1 to B15 described herein.

(B18) In yet another aspect, any of the methods B1 to B15 describedabove are performed by a storage device including means for performingany of the methods described herein.

(B20) In yet another aspect, a storage system includes (1) a storagemedium (e.g., comprising one or more non-volatile storage devices, suchas flash memory devices) (2) one or more processors, and (3) memory(e.g., non-volatile memory or volatile memory in the storage system)storing one or more programs, which when executed by the one or moreprocessors cause the storage system to perform or control performance ofany of the methods B1 to B15 described herein.

(B21) In yet another aspect, some embodiments include a non-transitorycomputer readable storage medium, storing one or more programsconfigured for execution by one or more processors of a storage device,the one or more programs including instructions for performing any ofthe methods B1 to B15 described herein.

Numerous details are described herein in order to provide a thoroughunderstanding of the example embodiments illustrated in the accompanyingdrawings. However, some embodiments may be practiced without many of thespecific details, and the scope of the claims is only limited by thosefeatures and aspects specifically recited in the claims. Furthermore,well-known methods, components, and circuits have not been described inexhaustive detail so as not to unnecessarily obscure pertinent aspectsof the embodiments described herein.

FIG. 1 is a block diagram illustrating data storage system 100, inaccordance with some embodiments. While some example features areillustrated, various other features have not been illustrated for thesake of brevity and so as not to obscure pertinent aspects of theexample embodiments disclosed herein. To that end, as a non-limitingexample, data storage system 100 includes a storage device 120, whichincludes a storage controller 124 and a storage medium 130, and is usedin conjunction with or includes a computer system 110. In someembodiments, storage medium 130 is a single flash memory device while inother embodiments storage medium 130 includes a plurality of flashmemory devices. In some embodiments, storage medium 130 is NAND-typeflash memory or NOR-type flash memory. In some embodiments, storagemedium 130 includes one or more three-dimensional (3D) memory devices,as further defined herein. Further, in some embodiments storagecontroller 124 is a solid-state drive (SSD) controller. However, othertypes of storage media may be included in accordance with aspects of awide variety of embodiments (e.g., PCRAM, ReRAM, STT-RAM, etc.). In someembodiments, a flash memory device includes one or more flash memorydie, one or more flash memory packages, one or more flash memorychannels or the like. In some embodiments, data storage system 100 cancontain one or more storage device 120 s.

Computer system 110 is coupled to storage controller 124 through dataconnections 101. However, in some embodiments computer system 110includes storage controller 124, or a portion of storage controller 124,as a component and/or a subsystem. For example, in some embodiments,some or all of the functionality of storage controller 124 isimplemented by software executed on computer system 110. Computer system110 may be any suitable computer device, such as a computer, a laptopcomputer, a tablet device, a netbook, an internet kiosk, a personaldigital assistant, a mobile phone, a smart phone, a gaming device, acomputer server, or any other computing device. Computer system 110 issometimes called a host, host system, client, or client system. In someembodiments, computer system 110 is a server system, such as a serversystem in a data center. In some embodiments, computer system 110includes one or more processors, one or more types of memory, a displayand/or other user interface components such as a keyboard, a touchscreen display, a mouse, a track-pad, a digital camera and/or any numberof supplemental devices to add functionality. In some embodiments,computer system 110 does not have a display and other user interfacecomponents.

Storage medium 130 is coupled to storage controller 124 throughconnections 103. Connections 103 are sometimes called data connections,but typically convey commands in addition to data, and optionally conveymetadata, error correction information and/or other information inaddition to data values to be stored in storage medium 130 and datavalues read from storage medium 130. In some embodiments, however,storage controller 124 and storage medium 130 are included in the samedevice (i.e., an integral device) as components thereof. Furthermore, insome embodiments, storage controller 124 and storage medium 130 areembedded in a host device (e.g., computer system 110), such as a mobiledevice, tablet, other computer or computer controlled device, and themethods described herein are performed, at least in part, by theembedded memory controller. Storage medium 130 may include any number(e.g., one or more) of memory devices including, without limitation,non-volatile semiconductor memory devices, such as flash memorydevice(s). For example, flash memory device(s) can be configured forenterprise storage suitable for applications such as cloud computing,for database applications, primary and/or secondary storage, or forcaching data stored (or to be stored) in secondary storage, such as harddisk drives. Additionally and/or alternatively, flash memory device(s)can also be configured for relatively smaller-scale applications such aspersonal flash drives or hard-disk replacements for personal, laptop,and tablet computers. In some embodiments, storage medium 130 includesone or more three-dimensional (3D) memory devices, as further definedherein.

Storage medium 130 is divided into a number of addressable andindividually selectable blocks, such as selectable portion 131. In someembodiments, the individually selectable blocks are the minimum sizeerasable units in a flash memory device. In other words, each blockcontains the minimum number of memory cells that can be erasedsimultaneously. Each block is usually further divided into a pluralityof pages and/or word lines, where each page or word line is typically aninstance of the smallest individually accessible (readable) portion in ablock. In some embodiments (e.g., using some types of flash memory), thesmallest individually accessible unit of a data set, however, is asector, which is a subunit of a page. That is, a block includes aplurality of pages, each page contains a plurality of sectors, and eachsector is the minimum unit of data for reading data from the flashmemory device.

As noted above, while data storage densities of non-volatilesemiconductor memory devices are generally increasing, a drawback ofincreasing storage density is that the stored data is more prone tobeing stored and/or read erroneously. In some embodiments, error controlcoding can be utilized to limit the number of uncorrectable errors thatare introduced by electrical fluctuations, defects in the storagemedium, operating conditions, device history, write-read circuitry,etc., or a combination of these and various other factors.

In some embodiments, storage controller 124 includes a management module121, a host interface 129, a storage medium I/O interface 128, andadditional module(s) 125. Storage controller 124 may include variousadditional features that have not been illustrated for the sake ofbrevity and so as not to obscure pertinent features of the exampleembodiments disclosed herein, and a different arrangement of featuresmay be possible. Host interface 129 provides an interface to computersystem 110 through data connections 101. Similarly, storage medium I/O128 provides an interface to storage medium 130 though connections 103.In some embodiments, storage medium I/O 128 includes read and writecircuitry, including circuitry capable of providing reading signals tostorage medium 130 (e.g., reading threshold voltages for NAND-type flashmemory).

In some embodiments, management module 121 includes one or moreprocessing units (CPUs, also sometimes called processors) 122 configuredto execute instructions in one or more programs (e.g., in managementmodule 121). In some embodiments, the one or more CPUs 122 are shared byone or more components within (e.g., Front End (FE) 126 and FlashManager (FM) 127), and in some cases, beyond the function of storagecontroller 124. Management module 121 is coupled to host interface 129,additional module(s) 125 and storage medium I/O 128 in order tocoordinate the operation of these components. In some embodiments, oneor more modules of management module 121 are implemented in a managementmodule of computer system 110 (not shown). In some embodiments, one ormore processors of computer system 110 (not shown) are configured toexecute instructions in one or more programs in the management module ofcomputer system 110 (not shown) and the management module of computersystem 110 is coupled to storage device 120 in order to manage theoperation of storage device 120.

Additional module(s) 125 are coupled to storage medium I/O 128, hostinterface 129, and management module 121. As an example, additionalmodule(s) 125 may include an error control module to limit the number ofuncorrectable errors inadvertently introduced into data during writes tomemory or reads from memory. In some embodiments, additional module(s)125 are executed in software by the one or more CPUs 122 of managementmodule 121, and, in other embodiments, additional module(s) 125 areimplemented in whole or in part using special purpose circuitry (e.g.,to perform encoding and decoding functions). In some embodiments,additional module(s) 125 are implemented in whole or in part by softwareexecuted on computer system 110.

In some embodiments, an error control module, included in additionalmodule(s) 125, includes an encoder and a decoder. In some embodiments,the encoder encodes data by applying an error control code to produce acodeword, which is subsequently stored in storage medium 130. When theencoded data (e.g., one or more codewords) is read from storage medium130, the decoder applies a decoding process to the encoded data torecover the data, and to correct errors in the recovered data within theerror correcting capability of the error control code. Those skilled inthe art will appreciate that various error control codes have differenterror detection and correction capacities, and that particular codes areselected for various applications for reasons beyond the scope of thisdisclosure. As such, an exhaustive review of the various types of errorcontrol codes is not provided herein. Moreover, those skilled in the artwill appreciate that each type or family of error control codes may haveencoding and decoding algorithms that are particular to the type orfamily of error control codes. On the other hand, some algorithms may beutilized at least to some extent in the decoding of a number ofdifferent types or families of error control codes. As such, for thesake of brevity, an exhaustive description of the various types ofencoding and decoding algorithms generally available and known to thoseskilled in the art is not provided herein.

In some embodiments, during a write operation, host interface 129receives data to be stored in storage medium 130 from computer system110. The data received by host interface 129 is made available to anencoder (e.g., in additional module(s) 125), which encodes the data toproduce one or more codewords. The one or more codewords are madeavailable to storage medium I/O 128, which transfers the one or morecodewords to storage medium 130 in a manner dependent on the type ofstorage medium being utilized.

In some embodiments, a read operation is initiated when computer system(host) 110 sends one or more host read commands (e.g., via dataconnections 101, or alternatively a separate control line or bus) tostorage controller 124 requesting data from storage medium 130. Storagecontroller 124 sends one or more read access commands to storage medium130, via storage medium I/O 128, to obtain raw read data in accordancewith memory locations (addresses) specified by the one or more host readcommands. Storage medium I/O 128 provides the raw read data (e.g.,comprising one or more codewords) to a decoder (e.g., in additionalmodule(s) 125). If the decoding is successful, the decoded data isprovided to host interface 129, where the decoded data is made availableto computer system 110. In some embodiments, if the decoding is notsuccessful, storage controller 124 may resort to a number of remedialactions or provide an indication of an irresolvable error condition.

As explained above, a storage medium (e.g., storage medium 130) isdivided into a number of addressable and individually selectable blocksand each block is optionally (but typically) further divided into aplurality of pages and/or word lines and/or sectors. While erasure of astorage medium is performed on a block basis, in many embodiments,reading and programming of the storage medium is performed on a smallersubunit of a block (e.g., on a page basis, word line basis, or sectorbasis). In some embodiments, the smaller subunit of a block consists ofmultiple memory cells (e.g., single-level cells or multi-level cells).In some embodiments, programming is performed on an entire page. In someembodiments, a multi-level cell (MLC) NAND flash typically has fourpossible states per cell, yielding two bits of information per cell.Further, in some embodiments, a MLC NAND has two page types: (1) a lowerpage (sometimes called fast page), and (2) an upper page (sometimescalled slow page). In some embodiments, a triple-level cell (TLC) NANDflash has eight possible states per cell, yielding three bits ofinformation per cell. Although the description herein uses TLC, MLC, andSLC as examples, those skilled in the art will appreciate that theembodiments described herein may be extended to memory cells that havemore than eight possible states per cell, yielding more than three bitsof information per cell.

The encoding format of the storage media (e.g., TLC, MLC, or SLC and/ora chosen data redundancy mechanism) is a choice made when data isactually written to the storage media. Often in this specification thereis described an event, condition, or process that is said to set theencoding format, alter the encoding format of the storage media, etc. Itshould be recognized that the actual process may involve multiple steps,e.g., erasure of the previous contents of the storage media followed bythe data being written using the new encoding format and that theseoperations may be separated in time from the initiating event, conditionor procedure.

As an example, if data is written to a storage medium in pages, but thestorage medium is erased in blocks, pages in the storage medium maycontain invalid (e.g., stale) data, but those pages cannot beoverwritten until the whole block containing those pages is erased. Inorder to write to the pages with invalid data, the pages (if any) withvalid data in that block are read and re-written to a new block and theold block is erased (or put on a queue for erasing). This process iscalled garbage collection. After garbage collection, the new blockcontains the pages with valid data and may have free pages that areavailable for new data to be written, and the old block can be erased soas to be available for new data to be written. Since flash memory canonly be programmed and erased a limited number of times, the efficiencyof the algorithm used to pick the next block(s) to re-write and erasehas a significant impact on the lifetime and reliability of flash-basedstorage systems. Further, blindly gathering valid data in a source block(e.g., the old block) and re-writing the valid data to a destinationblock (e.g., the new block) can degrade the performance of host readoperations after garbage collection.

As used herein, the term “host” or “host system” may be construed tomean (1) a computer system (e.g., computer system 110, FIG. 1) on behalfof which data is stored in a storage system (e.g., data storage system100, FIG. 1), (2) a storage system controller of a storage system, (3) acluster controller of a storage system, and/or (4) any computing entity(e.g., a computer, a process running on a computer, a mobile phone, aninternet kiosk, a tablet computer, a laptop computer, a desktopcomputer, a server computer, etc.) that is operatively coupled eitherdirectly or indirectly to a storage system, depending on the context.Further, in some contexts, the host is or includes a client or clientsystem, on behalf of which data is stored in a storage system.

FIG. 2 is a block diagram illustrating a management module 121 inaccordance with some embodiments, as shown in FIG. 1. Management module121 typically includes one or more processing units (sometimes calledCPUs or processors) 122 for executing modules, programs and/orinstructions stored in memory 206 and thereby performing processingoperations, memory 206 (sometimes called controller memory), and one ormore communication buses 208 for interconnecting these components.Management module 121 optionally includes front end (FE) 126, which isresponsible for tasks such as updating address tables (e.g., translationtable 212), deciding which source blocks to garbage collect, anddeciding when to perform garbage collection. Further, management module121 optionally includes flash manager (FM) 127, which is responsible forcarrying out garbage collection commands from front end 126. The one ormore communication buses 208 optionally include circuitry (sometimescalled a chipset) that interconnects and controls communications betweensystem components. Management module 121 is coupled to host interface129, additional module(s) 125, and storage medium I/O 128 by the one ormore communication buses 208. Memory 206 includes high-speed randomaccess memory, such as DRAM, SRAM, DDR RAM or other random access solidstate memory devices, and may include non-volatile memory, such as oneor more magnetic disk storage devices, optical disk storage devices,flash memory devices, or other non-volatile solid state storage devices.Memory 206 optionally includes one or more storage devices remotelylocated from the CPU(s) 122. Memory 206, or alternatively thenon-volatile memory device(s) within memory 206, comprises anon-transitory computer readable storage medium. In some embodiments,memory 206, or the non-transitory computer readable storage medium ofmemory 206 stores the following programs, modules, and data structures,or a subset or superset thereof:

-   translation table 212 that is used for mapping logical addresses to    physical addresses;-   data read module 214 that is used for reading data from one or more    codewords, pages or blocks in a storage medium (e.g., storage medium    130, FIG. 1);-   data write module 216 that is used for writing data to one or more    codewords, pages or blocks in a storage medium (e.g., storage medium    130, FIG. 1);-   data erase module 218 that is used for erasing data from one or more    blocks in a storage medium (e.g., storage medium 130, FIG. 1);-   receiving module 220 that is used for receiving garbage collection    requests; in some embodiments each garbage collection request    specifies a source unit from which valid data is to be garbage    collected; and-   garbage collection module 230 that is used for garbage collection    for one or more blocks in a storage medium (e.g., storage medium    130, FIG. 1), optionally including:    -   garbage collection (GC) read module 232 that is used for        performing one or more operations for a garbage collection read;    -   garbage collection (GC) write module 242 that is used for        performing one or more operations for a garbage collection        write;    -   allocating module 236 that is used for allocating one or more        queues for garbage collection (e.g., in garbage collection read        buffer pool 420, FIG. 4A);    -   rearranging module 238 that is used for rearranging one or more        sequences of valid data in garbage collection queues (e.g., in        garbage collection read buffer pool 420, FIG. 4A) to group        logically sequential data together; and    -   marking module 240 that is used for marking blocks as eligible        for erasing after completion of garbage collection.

In some embodiments, memory 206, or the non-transitory computer readablestorage medium of memory 206 stores front end (FE) 126, implemented as asoftware module, and flash manager (FM) 127, also implemented as asoftware module. In some embodiments, flash manager (FM) 127 includesreceiving module 220 and garbage collection module 230. In someembodiments, flash manager (FM) 127 also includes data read module 214,data write module 216, and data erase module 218, or portions of thosemodules.

In some embodiments, memory 206, or the non-transitory computer readablestorage medium of memory 206 includes garbage collection read bufferpool 320/420, and the queues (e.g., queues 422-436) implemented ingarbage collection read buffer pool 320/420 (see FIGS. 3 and 4A).

Each of the above identified elements may be stored in one or more ofthe previously mentioned memory devices, and corresponds to a set ofinstructions for performing a function described above. The aboveidentified modules or programs (e.g., sets of instructions) need not beimplemented as separate software programs, procedures or modules, andthus various subsets of these modules may be combined or otherwisere-arranged in various embodiments. In some embodiments, memory 206 maystore a subset of the modules and data structures identified above.Furthermore, memory 206 may store additional modules and data structuresnot described above. In some embodiments, the programs, modules, anddata structures stored in memory 206, or the non-transitory computerreadable storage medium of memory 206, provide instructions forimplementing some of the methods described below. In some embodiments,some or all of these modules may be implemented with specializedhardware circuits that subsume part or all of the module functionality.

Although FIG. 2 shows management module 121 in accordance with someembodiments, FIG. 2 is intended more as a functional description of thevarious features which may be present in management module 121 than as astructural schematic of the embodiments described herein. In practice,and as recognized by those of ordinary skill in the art, the programs,modules, and data structures shown separately could be combined and someprograms, modules, and data structures could be separated.

FIG. 3 illustrates a conventional implementation of garbage collection.As described above, garbage collection is a process of memory managementthat reclaims portions of memory that no longer contain valid data. Ifsome portions of one or more source blocks (e.g., source block 302 andsource block 308) contain invalid data, those portions cannot beoverwritten until the whole block is erased. The process of garbagecollection reads and re-writes the pages with valid data from the one ormore source blocks (e.g., source block 302 and source block 308) intoone or more destination blocks (e.g., destination block 340) and thenerases the source blocks.

In the example of FIG. 3, valid data from source blocks 302 and 308 arecopied into a temporary buffer (e.g., garbage collection read bufferpool 320), at the minimum granularity possible (e.g., 4K), and then thevalid data is written to destination block 340 in a first to last order.This conventional implementation of garbage collection is subject to thebuffers becoming interleaved due to multiple source blocks from multiplechannels transferring data into the buffer pool (e.g., garbagecollection read buffer pool 320). Even in the case where valid data fromsource blocks is copied into the temporary buffer one source block at atime (as illustrated in FIG. 3), physically sequential runs of validdata may become separated and unaligned with plane or sub planeboundaries.

As shown in FIG. 3, each box with an indicator (e.g., A1, B1, C1, etc.)illustrates a valid logical page (sometimes called an “L-page” or a “4Krun”) and adjacent boxes with the same letter indicator (e.g., D1, D2,D3, and D4) illustrate that the data is physically sequential. In thisexample, a block is 96K, consisting of 24 logical pages of 4K each, withan upper page, a middle page, and a lower page. For example, sourceblock 302 has an upper page (e.g., page 304-3), a middle page (e.g.,page 304-2), and a lower page (e.g., page 304-1), where the lower page304-1 has 8 logical pages (e.g., L-pages 306-1 through 306-8), where inthe lower page 304-1, L-pages 306-1, 306-3, 306-5 and 306-6 are validL-pages (e.g., with valid data A1, B1, C1, and C2, respectively) andL-pages 306-2, 306-4, 306-7, and 306-8 are invalid L-pages (e.g., nolonger contain valid data). Similarly, source block 308 has an upperpage (e.g., page 310-3), a middle page (e.g., page 310-2), and a lowerpage (e.g., page 310-1), where the lower page 310-1 has 8 logical pages(e.g., L-pages 312-1 through 312-8), where in the lower page 310-1,L-pages 312-2, 312-3, 312-4, and 312-8 are valid L-pages (e.g., withvalid data F1, F2, F3, and G1, respectively) and L-pages 312-1, 312-5,312-6, and 312-7 are invalid L-pages (e.g., no longer contain validdata).

As valid data is read from the source blocks, garbage collection readbuffer pool 320 is filled in page order, from lower page to middle pageto upper page. Although it is possible that reads from source block 302and source block 308 may be interleaved in garbage collection readbuffer pool 320, in the example of FIG. 3, it is assumed that all validdata from source block 302 is read before reading valid data from sourceblock 308. Once the valid data is populated in garbage collection readbuffer pool 320, physically sequential runs are no longer distinguishedand the buffers are treated equally as 4K units of valid data. Then,data is drained in 96K (e.g., a full sequence page, including lowerpage, middle page, and upper page, or 24 4K buffers) chunks to thedestination block (e.g., destination block 340), where the 96K is takenfrom the beginning of garbage collection read buffer pool 320 andcontains the set of 4K buffers in the 96K range. In conventional garbagecollection, there is no heuristic to select buffers from buffer pool 320for writing to destination block 340, so the first 24 buffers fromgarbage collection read buffer pool 320 are selected for the garbagecollection write.

Blindly gathering valid data in this manner can degrade the performanceof host read operations after garbage collection. For example, aftergarbage collection, the full middle page 310-2 from source block 308that contained valid data H1 through H8 is split across two pages ofdestination block 340 (e.g., H1 is in middle page 342-2 and H2 throughH8 are in upper page 342-3). To read the sequential chunk of H1 throughH8, two sense commands would be required after garbage collection (toread H1 through H8 from destination block 340), where only one sensecommand was required prior to garbage collection (to read H1 through H8from source block 308). Further, if wordlines are further divided intoplanes and sub planes (e.g., as shown in destination block 340), ifsingle plane reads (e.g., reading plane 0 or plane 1) or fast reads(e.g., reading one or more sub planes) are used to reduce the sensetime, maintaining sub-plane boundaries are beneficial. However,conventional garbage collection, as shown in FIG. 3, does not maintainplane or sub-plane boundaries.

FIGS. 4A-4B illustrate locality grouping during garbage collection, inaccordance with some embodiments. FIG. 4A illustrates a garbagecollection read, in accordance with some embodiments, and FIG. 4Billustrates a garbage collection write, in accordance with someembodiments. As shown in FIG. 4A, instead of allocating garbagecollection buffers with a 4K granularity (as shown in FIG. 3), garbagecollection buffers are allocated with a virtual 16K granularity (e.g.,with four 4K buffers), which are allocated and freed atomically. As avalid bitmap for a source block (e.g., a bitmap indicating which L-pagesin the source block contain valid data) is processed, 16K-sized queues(sometimes called “extents” or “queue extents”) of a particular type(e.g., 4K queue, 8K queue, or 16K queue) are allocated as needed, andsequential sequences (sometimes called “runs”) of valid data aretransferred from the source block to an appropriate queue (e.g., 4Kqueue, 8K queue, or 16K queue), according to the length of thesequential sequence of valid data. If a queue of a specific size isfilled or not yet allocated, another queue of that size is allocated, asneeded. In this manner, sequential runs of valid data are preserved andsingle (e.g., random) L-pages are not mixed with sequential runs. Insome embodiments, front end 126 determines which source blocks are to begarbage collected. In some embodiments, flash manager 127 receivesgarbage collection read requests and garbage collection write requestsfrom front end 126.

FIG. 4A illustrates a garbage collection read, in accordance with someembodiments. In the example in FIG. 4A, as valid data is read from thesource blocks, garbage collection read buffer pool 420 is filled in pageorder from the source blocks, from lower page to middle page to upperpage (e.g., lower page 404-1 to middle page 404-2 to upper page 404-3 ofsource block 402). Although it is possible that reads from source block402 and source block 408 may be interleaved, in the example of FIG. 4A,it is assumed that all valid data from source block 402 is read beforereading valid data from source block 408. As source block 402 isprocessed (e.g., in accordance with a valid bitmap for source block402), lower page 404-1 is processed first. A1 in L-page 406-1 isidentified as a single L-page of valid data (e.g., a “4K run” of validdata, where there is not a sequential run of valid data), and a16K-sized queue for 4K length sequences (e.g., 4K queue 422) isallocated in garbage collection read buffer pool 420. Then, valid dataA1 is transferred to 4K queue 422. Continuing to process lower page404-1 from source block 402, B1 in L-page 406-3 is identified as asingle L-page of valid data. Since an open queue for 4K length sequences(e.g., 4K queue 422) is already allocated and has space available, validdata B1 is transferred to 4K queue 422. Continuing to process lower page404-1 from source block 402, C1-C2 is identified as a sequence of validdata with a length of 8K (e.g., an “8K run” of valid data). Since thereis no available queue for 8K length sequences, a 16K-sized queue for 8Klength sequences (e.g., 8K queue 424) is allocated, using availablebuffers in garbage collection read buffer pool 420. Then valid dataC1-C2 is transferred to 8K queue 424.

This process continues for the remaining pages of source block 402(e.g., middle page 404-2 and upper page 404-3) to identify and transfersequences of valid data (e.g., D1-D4 and E1 from middle page 404-2, andE2-E3 from upper page 404-3), and for the pages of source block 408(e.g., lower page 410-1, middle page 410-2, and upper page 410-3, andL-pages 412-1 to 412-8) to identify and transfer sequences of valid data(e.g., L3-L6 and L1-L2 from lower page 410-1, N1-N2, M1, and N3 frommiddle page 410-2, and O1-O4 and O5-O8 from upper page 410-3) in L-pages412-1 to 412-8. It is noted that the E1-E3 run of valid data was splitacross middle page 404-2 and upper page 404-3 of source block 402 andwas treated as two independent runs of valid data (e.g., E1 and E2-E3).Further, the L1-L6 run of valid data and the N1-N3 run of valid data aresplit into different queue extents. The process and order in whichsequences of valid data are identified are discussed below with respectto FIG. 5. As explained below, the algorithm identifies sequences ofvalid data of 16K, 8K, or 4K lengths and does not look for 24K runs, 32Kruns or other odd-sized runs to attempt to maintain them. Although notshown here, in some embodiments, the algorithm identifies and storesother sizes of valid data runs (e.g., 12K, 24K, 32K, etc.). In suchcases, the granularity of the queue extent is sized differently (e.g.,with larger than 16K queue extents) to accommodate and maintain thedifferent sizes of valid data runs. Despite splitting up the runs ofvalid data, the algorithm does not reduce the performance of the hostread after garbage collection. In some cases, as discussed below withrespect to FIGS. 7A-7B, the performance is improved, as sense operationswhich would have previously been on the same die can now be done inparallel since the valid data is split across more than one die and/orchannel. Note that, in some embodiments, the order in which queues areallocated and/or that data is assigned to those queues may vary from theexamples given here, for example in FIGS. 4A and 5.

FIG. 4B illustrates a garbage collection write, in accordance with someembodiments. After the garbage collection read in which valid data isread from the source blocks (as described above with respect to FIG.4A), there is enough valid data to complete a 96K garbage collectionwrite. In the example of FIG. 4B, full queues (e.g., queues that arecomplete) are identified for writing to destination block 440. Two fullqueues have enough valid data for a 32K physical page of a destinationblock and three sets of two full queues provide 96K of valid data for agarbage collection write to destination block 440. The queue extents arewritten for the garbage collection write from the oldest to newest,taking only full extents to fill the garbage collection write page.Here, 4K queue 422 and 8K queue 424 are written into the lower page ofdestination block 440, 16K queue 426 and 16K queue 428 are written intothe middle page of destination block 440, and 8K queue 430 and 16K queue434 are written into the upper page of destination block 440. When thevalid data from the queues is written to the destination block, thequeue extents are released, leaving two extents allocated (e.g., 4Kqueue 432 and 16K queue 436) at the end of the garbage collection write.

FIG. 5 illustrates various patterns used to detect sequences (sometimescalled “runs”) of valid data, in accordance with some embodiments. Oneof the goals for detecting sequences of valid data is to keep processingto a minimum. Some conventional methods for detecting runs of valid datafor garbage collection can be processor-intensive. Here, however, usinga bitmask (or pattern) to detect sequences of valid data minimizesprocessing. As shown in FIG. 5, the illustrated set of patterns aretested against the valid bitmap for a particular page of a source block(e.g., page 504-1 of source block 502) to identify sequences of validdata in the source block and to which type of queue (e.g., 16K queue, 8Kqueue, or 4K queue) in the buffer pool the valid data should betransferred. FIG. 5 illustrates three patterns to check for 16K runs,four patterns to check for 8K runs, and eight patterns to check for 4Kruns, where the patterns are checked in the order illustrated (e.g., 16Kpatterns are checked prior to 8K patterns, which are checked prior to 4Kpatterns) to maximally preserve sequential runs of valid data. Note thatif the sequence of valid data does not match the larger run sizes (e.g.,16K patterns and 8K patterns), by process of elimination, the remainingvalid data must match the smallest run size (e.g., 4K), which reducesthe processing needed for detecting sequences of valid data. Thepatterns identify sequences of valid data of 16K, 8K, or 4K lengths anddo not look for 24K runs, 32K runs, or other odd-sized/odd-aligned runsto attempt to maintain them. By using only three types of queue extents(e.g., 16K, 8K, or 4K), multiple benefits are obtained: (1) the overheadis lower, (2) 8K alignment is preserved, so data which would havepreviously been able to be read with a fast read (e.g., by reading a subplane) can still be read with a fast read, and (3) the valid bitmappatterns used to identify queue extents to which valid data is to betransferred can be kept to a minimum number of patterns.

FIGS. 6A-6C illustrate garbage collection writes with incomplete (e.g.,not full) queues, in accordance with some embodiments. As discussedabove with respect to FIGS. 4A-4B, when allocating garbage collectionbuffers with a 16K granularity (which are allocated and freedatomically), it is possible that some of the queue extents are leftincompletely filled with valid data (e.g., 4K queue 432, FIG. 4B), afterall valid data has been read from a source block. Incompletely filledqueue extents are sometimes called incomplete queue extents. In FIG. 4B,since only complete queue extents are written when filling the pages ofa destination block for a garbage collection write, there may be somequeue extents that are left incomplete for a significant length of time.This causes a problem for two reasons. First, incomplete queue extentsdo not use the garbage collection read buffer pool efficiently (e.g., insome implementations, where buffers are not allocated just in time, whenthe data is about to be transferred), which could lead to requirementsfor a larger buffer pool. Second, and more importantly, if the validdata which resides in an incomplete queue extent becomes the last validL-page(s) in a source block, the open queue extent prevents the sourceblock from being closed and eligible for erasing. This leads tosignificant trapped over provisioning in the storage device and may leadto increased garbage collection in order to free space from otherblocks.

In some embodiments, the solution to this issue is to tag the garbagecollection read request that contains the last valid pages in the sourceblock (e.g., the read request is the last read needed to completegarbage collection of the source block). Then, when performing thegarbage collection read (e.g., the final garbage collection read for thesource block), in addition to identifying sequences of valid data andtransferring them to appropriate queue extents (as discussed above withrespect to FIG. 4B), a global flag is set to indicate that the nextgarbage collection write request should flush all open queue extents(e.g., including incomplete queue extents). This guarantees that anyvalid data waiting in an incomplete queue extent will be written and thesource block can be closed at the end of the garbage collection writeoperation. This solution does mean that there will be unused space inthe destination block, as described below in FIGS. 6A-6C. At most, it ispossible for five 4K buffers to be “wasted” or unused in the incompletequeue extents (as shown in FIG. 6C). However, as shown below in FIGS.6A-6C, this is not the worst case in terms of unused space in thedestination block. In the examples shown below, five unused 4K buffersresults in just one unused 4K page in the destination block, but threeunused 4K buffers (see FIG. 6A) results in three unused 4K pages in thedestination block.

FIGS. 6A-6C illustrate the possible combinations of incomplete queueextents and how they are optimally mapped to the destination block in agarbage collection write. In each case, the empty 4K buffers are placedin the middle page because the middle page in BiCS NAND (bit-costscalable NAND, which is one type or class of 3D NAND devices) has theslowest read and is the least desirable place for data to be written.Thus, in some embodiments, the invalid or unused L-pages are placed inthe middle page. However, the L-pages which are invalid are not lefterased, since this is undesirable from the NAND perspective. Rather, insome embodiments, these invalid L-pages are padded with random data(e.g., a copy of another valid L-page, or simply random data from theread buffer pool). Since these invalid L-pages will never be referenced,the content of the data is not important.

FIG. 6A illustrates one combination of incomplete queue extents wherethree 4K buffers are unused in garbage collection read buffer pool 620.Here, 8K queue 624 and 16K queue 626 are written into the lower page ofdestination block 640, incomplete 8K queue 628 and incomplete 4K queue622 are written into the middle page of destination block 640, and 16Kqueue 630 and 16K queue 632 are written into the upper page ofdestination block 640. After this garbage collection write, there arethree L-pages (of 4K each) of unused space in destination block 640,which is the worst case scenario of unused space in the destinationblock. As shown below in FIGS. 6B-6C, even when there are additionalunused 4K buffers in the incomplete queue extents, there is less unusedspace in the destination block.

FIG. 6B illustrates another combination of incomplete queue extentswhere four 4K buffers are unused in garbage collection read buffer pool650. Here, incomplete 8K queue 658, incomplete 4K queue 652, and 16Kqueue 656 are written into the lower page of destination block 670, 8Kqueue 654 and 16K queue 660 are written into the middle page ofdestination block 670, and 16K queue 662 and 16K queue 664 are writteninto the upper page of destination block 670. After this garbagecollection write, there is no unused space in destination block 670,despite four 4K buffers of unused space in the queue extents.

FIG. 6C illustrates yet another combination of incomplete queue extentswhere five 4K buffers are unused in garbage collection read buffer pool680. Here, 8K queue 684 and 16K queue 690 are written into the lowerpage of destination block 696, 16K queue 686, incomplete 8K queue 688,and incomplete 4K queue 682 are written into the middle page ofdestination block 696, and 16K queue 692 and 16K queue 694 are writteninto the upper page of destination block 696. After this garbagecollection write, there is one L-page of unused space in destinationblock 696, despite five 4K buffers of unused space in the queue extents.

FIGS. 7A-7B illustrate locality grouping during garbage collection withmultiple memory channels, in accordance with some embodiments. In someembodiments, the methods shown in the previous examples are furtherimproved by taking into account the logical nature of the data. In theprevious examples, the garbage collection read and write operationsrelied on the valid bitmap for the source block, which indicatesphysical adjacency. In many cases, this physical adjacency will also mapto logical adjacency. In some embodiments, the storage device (e.g.,Flash Manager 127) maintains a Flash Translation Index (FTI) with theprevious physical address (e.g., the source physical location from whichthe valid data was read) and the new physical address (e.g., thedestination physical location where the valid data is written). In someembodiments, this information is passed to Front End 126 from FlashManager 127 when the garbage collection write is completed to enablecorrectly updating translation table 212 (FIG. 2).

In some embodiments, using the Flash Translation Index, Flash Manager127 uses the stored logical information in conjunction with the queueextents to improve the performance of the system after garbagecollection. As shown in FIG. 7A, valid data from source blocks 702, 704,706, and 708 are written into garbage collection read buffer pool 720during one or more garbage collection reads. In FIG. 7B, instead ofwriting a full 96K sequence page to a single channel/die before movingto the next channel/die to write the next 96K, based on the logicalinformation, 96K logically sequential runs are spread across multiplechannels (e.g., in destination blocks 712, 714, 716 and 718 of channels0, 1, 2 and 3, respectively), thereby increasing the parallelismpossible for future host reads of the sequential data.

FIGS. 8A-8E illustrate a flowchart representation of a method 800 ofoperating a storage device that includes non-volatile memory, inaccordance with some embodiments. At least in some embodiments, method800 is performed by a storage device (e.g., storage device 120, FIG. 1)or one or more components of the storage device (e.g., storagecontroller 124, FIG. 1), wherein the storage device is operativelycoupled with a host system (e.g., computer system 110, FIG. 1). In someembodiments, method 800 is governed by instructions that are stored in anon-transitory computer readable storage medium and that are executed byone or more processors of a device, such as the one or more processingunits (CPUs) 122 of management module 121, shown in FIGS. 1 and 2. Insome embodiments, method 800 is performed by a storage system (e.g.,data storage system 100, FIG. 1) or one or more components of thestorage system (e.g., storage device 120, FIG. 1). In some embodiments,some of the operations of method 800 are performed at a storage device(e.g., storage device 120, FIG. 1) and information is transmitted to ahost (e.g., computer system 110, FIG. 1).

At a storage controller for the storage device (802), the storage device(e.g., storage device 120, FIG. 1) receives (806) a plurality of garbagecollection requests, wherein each garbage collection request specifies asource unit (e.g., a 96K source unit to garbage collect, such as sourceblock 402 and/or source block 408, FIG. 4A). In some embodiments, areceiving module (e.g., receiving module 220, FIG. 2) is used to receivea plurality of garbage collection requests, wherein each garbagecollection request specifies a source unit, as described above withrespect to FIG. 2. In some embodiments, garbage collection requests areproduced by a module (e.g., Front End module 126, FIGS. 1 and 2, orother not shown module) that detects a trigger condition, such as thenumber of erased blocks available for writing data falling below athreshold number, and that upon detecting the trigger condition,identifies, in accordance with predefined selection criteria, one ormore blocks to be garbage collected. In some embodiments, the predefinedselection criteria include, as at least one factor that prioritizesgarbage collection of blocks having the least amount of valid data.

In some embodiments, the storage device comprises (804) one or moreflash memory devices. In some embodiments, the storage device comprisesa storage medium (e.g., storage medium 130, FIG. 1), and the storagemedium comprises one or more non-volatile storage devices, such as flashmemory devices. In some embodiments, the storage medium (e.g., storagemedium 130, FIG. 1) is a single flash memory device, while in otherembodiments the storage medium includes a plurality of flash memorydevices. For example, in some embodiments, the storage medium includesdozens or hundreds of flash memory devices, organized in parallel memorychannels, such as 16, 32 or 64 flash memory devices per memory channel,and 8, 16 or 32 parallel memory channels. In some embodiments, thenon-volatile storage medium (e.g., storage medium 130, FIG. 1) includesNAND-type flash memory or NOR-type flash memory. In other embodiments,the storage medium comprises one or more other types of non-volatilestorage devices.

The storage device (e.g., storage device 120, FIG. 1), in response toreceiving a garbage collection request of the plurality of garbagecollection requests, performs (808) one or more operations for a garbagecollection read, including: identifying (e.g., in accordance with avalid bitmap for the source unit) one or more sequences of valid data inthe source unit, wherein each identified sequence of valid data has alength selected from a set of predefined lengths, the set including afirst length (e.g., 4K), a second length (e.g., 8K), and a third length(e.g., 16K); and for each respective sequence of the one or moresequences of valid data in the source unit, transferring (e.g., readingand buffering) the respective sequence to a respective queue of aplurality of queues, in accordance with the length of the respectivesequence (e.g., as described above with respect to FIG. 4A). Although inthe examples here, the set of predefined lengths includes three lengths(e.g., 4K, 8K, and 16K), in some embodiments, the set of predefinedlengths includes N lengths, where N is an integer number determined byone or more factors (e.g., available space to store patterns, CPU timeto search for patterns, makeup of the NAND memory, host usage patterns,etc.). N is typically greater than 2.

In some embodiments, the valid bit map is specified by the garbagecollection read request, while in some other embodiments, the valid bitmap is obtained from a management data structure in accordance with thespecified source unit. In some embodiments, a garbage collection (GC)read module (e.g., GC read module 232, FIG. 2) is used to perform one ormore operations for a garbage collection read, including: identifyingone or more sequences of valid data in the source unit, wherein eachidentified sequence of valid data has a length selected from a set ofpredefined lengths, the set including a first length, a second length,and a third length; and for each respective sequence of the one or moresequences of valid data in the source unit, transferring the respectivesequence to a respective queue of a plurality of queues, in accordancewith the length of the respective sequence, as described above withrespect to FIG. 2.

In some embodiments, each sequence of the one or more sequences of validdata in the source unit includes (814) one or more logical pages ofvalid data. In some embodiments, a logical page (sometimes referred toas an “L-page”) is the minimum granularity unit of data (e.g., 4K) fordata read commands or data read operations.

In some embodiments, identifying the one or more sequences of valid datain the source unit includes (816): for each respective sequence of validdata, determining whether the respective sequence has the first length(e.g., 4K), the second length (e.g., 8K), or the third length (e.g.,16K) by: determining whether the respective sequence has the thirdlength; in accordance with a determination that the respective sequencedoes not have the third length, determining whether the respectivesequence has the second length; and in accordance with a determinationthat the respective sequence does not have the second length,determining whether the respective sequence has the first length. See,for example, FIG. 5 for patterns used to detect “runs” of valid data.

In some embodiments, transferring the respective sequence to therespective queue of the plurality of queues, in accordance with thelength of the respective sequence, includes (818): in accordance with adetermination that the respective sequence of valid data has the firstlength, transferring (e.g., reading and buffering) the respectivesequence of valid data into a first queue of a first type (e.g., a 4Kqueue extent that can hold four sequences of 4K length each, such as 4Kqueue 422, FIG. 4A); in accordance with a determination that therespective sequence of valid data has the second length, transferringthe respective sequence of valid data into a second queue of a secondtype (e.g., an 8K queue extent that can hold two sequences of 8K lengtheach, such as 8K queue 424, FIG. 4A); and in accordance with adetermination that the respective sequence of valid data has the thirdlength, transferring the respective sequence of valid data into a thirdqueue of a third type (e.g., a 16K queue extent that can hold onesequence of 16K length, such as 16K queue 426, FIG. 4A).

In some embodiments, the first queue, the second queue, and the thirdqueue are (820) the same size (e.g., 4 pages or 16K).

In some embodiments, in the plurality of queues, queues of the firsttype of queue each hold (822) single logical pages. For example, queuesof the first type of queue hold four sequences of 4K length each, eachsequence of 4K length sometimes referred to as a “4K run” (e.g., 4Kqueue 422, FIG. 4A).

In some embodiments, in the plurality of queues, queues of the secondtype of queue each hold (824) at least one sequence of logical pages ofat least the second length. For example, queues of the second type ofqueue hold two sequences of 8K length each, each sequence of 8K lengthsometimes referred to as an “8K run” (e.g., 8K queue 424, FIG. 4A).

In some embodiments, in the plurality of queues, queues of the thirdtype of queue each hold (826) at least one sequence of logical pages ofat least the third length. For example, queues of the third type ofqueue hold one sequence of 16K length, a sequence of 16K lengthsometimes referred to as a “16K run” (e.g., 16K queue 426, FIG. 4A).

In some embodiments, the storage device (e.g., storage device 120, FIG.1): in accordance with a determination that the first queue of the firsttype is full, allocates (828) a fourth queue of the first type; inaccordance with a determination that the second queue of the second typeis full, allocates a fifth queue of the second type; and in accordancewith a determination that the third queue of the third type is full,allocates a sixth queue of the third type. For example, in FIG. 4A, 16Kqueue 428 is allocated when 16K queue 426 is full, 8K queue 430 isallocated when 8K queue 424 is full, and 4K queue 432 is allocated when4K queue 422 is full. In some embodiments, an allocating module (e.g.,allocating module 236, FIG. 2) is used to allocate queues, as describedabove with respect to FIG. 2.

The storage device (e.g., storage device 120, FIG. 1), after performingthe one or more operations for the garbage collection read, performs(810) one or more operations for a garbage collection write, including:identifying full respective queues for writing to a destination unit(e.g., full respective queues are queues that are complete); and writingfrom the full respective queues to the destination unit (e.g., asdescribed above with respect to FIG. 4B). In some embodiments, a garbagecollection (GC) write module (e.g., GC write module 234, FIG. 2) isused, after performing the one or more operations for the garbagecollection read, to perform one or more operations for a garbagecollection write, including: identifying full respective queues forwriting to a destination unit and writing from the full respectivequeues to the destination unit, as described above with respect to FIG.2.

In some embodiments, the plurality of queues comprises (830) buffermemory distinct from non-volatile memory in the destination unit (e.g.,distinct from destination block 440, FIG. 4B).

In some embodiments, writing from the full respective queues to thedestination unit includes (832) writing from the full respective queuesin sequence, from an oldest full respective queue to a newest fullrespective queue, to the destination unit (e.g., as described above withrespect to FIG. 4B, where 4K queue 422 is the oldest full queue).

In some embodiments, writing from the full respective queues to thedestination unit includes (834) writing from the full respective queuesto the destination unit until the destination unit is full (e.g., asdescribed above with respect to FIG. 4B).

In some embodiments, identifying full respective queues and writing fromthe full respective queues includes (836): identifying full respectivequeues for writing to one or more destination units in one or morememory channels, respectively; in accordance with a determination thatat least N of the full respective queues are logically sequential, whereN is a predefined integer greater than one, writing the N fullrespective queues that are logically sequential to destination units inat least two different memory channels. In some embodiments, thepredefined integer (N) is determined based on the queue size and memorychannel width. For example, if the memory channel width is wider thanthe queue size (e.g., as shown in FIG. 7B), multiple full respectivequeues can fit in one memory channel, so N might need to be three ormore for the full queues to be written in two different memory channels.In some embodiments, the at least two different memory channels can beaccessed in parallel and/or concurrently.

In some embodiments, writing the N full respective queues that arelogically sequential to destination units in at least two differentmemory channels includes (838): writing from a first queue of the N fullrespective queues that are logically sequential to a first destinationunit of a first memory channel; and writing from a second queue of the Nfull respective queues that are logically sequential to a seconddestination unit of a second memory channel (e.g., as described abovewith respect to FIG. 7B).

In some embodiments, the storage controller for the storage deviceincludes (840) a first module (e.g., a front-end module, sometimesreferred to as the “Front End” or “FE”) (e.g., Front End 126, FIGS. 1and 2) and a second module (e.g., a back-end module, sometimes referredto as the “Flash Manager,” the “Flash Monitor,” and/or “FM”) (e.g.,Flash Manager 127, FIGS. 1 and 2). In some embodiments, receiving theplurality of garbage collection requests includes receiving, at thesecond module, a plurality of garbage collection read requests from thefirst module. In some embodiments, the one or more operations for thegarbage collection read are performed in response to receiving arespective garbage collection read request of the plurality of garbagecollection read requests.

In some embodiments, the storage device, prior to performing one or moreoperations for the garbage collection write, receives (842), at thesecond module, a garbage collection write request from the first module;and performs the one or more operations for the garbage collection writein response to receiving the garbage collection write request. In someembodiments, a receiving module (e.g., receiving module 220, FIG. 2) isused to receive, at the second module, a garbage collection writerequest from the first module and a garbage collection (GC) write module(e.g., GC write module 234, FIG. 2) is used to perform the one or moreoperations for the garbage collection write in response to receiving thegarbage collection write request, as described above with respect toFIG. 2. In some embodiments, a garbage collection write request isgenerated by the first module (e.g., front end 126) and sent to thesecond module (e.g., flash manager 127) when a garbage collection writetrigger condition is detected. In some embodiments, a garbage collectionwrite trigger condition is detected when the number of complete or fullqueues in garbage collection read buffer pool 320/420 reaches or exceedsa threshold number.

In some embodiments, the storage device, prior to performing the one ormore operations for the garbage collection write: in accordance withlogical address information, rearranges (812) one or more sequences ofvalid data in the plurality of queues to group logically sequential datatogether, wherein at least one queue in the plurality of queues has alonger sequence of logically sequential data after the rearranging thanbefore the rearranging. For example, in FIG. 4B, valid data N1-N3 issplit between two queues (e.g., 8K queue 430 and 4K queue 432). Iflogical address information shows that this sequence is logicallysequential (in addition to physically sequential as determined from thevalid bitmap), in some embodiments, prior to performing the one or moreoperations for the garbage collection write, the storage devicerearranges N1-N3 to keep the sequence together (e.g., by moving N1-N2 to4K queue 432 with N3, resulting in 4K queue 432 having a longer sequenceof logically sequential data after the rearranging than before therearranging). In some embodiments, a rearranging module (e.g.,rearranging module 238, FIG. 2) is used to rearrange one or moresequences of valid data in the plurality of queues to group logicallysequential data together, wherein at least one queue in the plurality ofqueues has a longer sequence of logically sequential data after therearranging than before the rearranging, as described above with respectto FIG. 2.

In some embodiments, any operations of method 800 described above areperformed by a storage device, the storage device including (1)non-volatile memory (e.g., comprising one or more non-volatile storagedevices, such as flash memory devices), (2) one or more processors, and(3) controller memory (e.g., non-volatile memory or volatile memory inor coupled to the controller) storing one or more programs, which whenexecuted by the one or more processors cause the storage device toperform or control performance of any of the methods described herein.

In some embodiments, any operations of method 800 described above areperformed by a storage device including means for performing any of themethods described herein.

In some embodiments, any operations of method 800 described above areperformed by a storage system comprising (1) a storage medium (e.g.,comprising one or more non-volatile storage devices, such as flashmemory devices) (2) one or more processors, and (3) memory (e.g.,non-volatile memory or volatile memory in the storage system) storingone or more programs, which when executed by the one or more processorscause the storage system to perform or control performance of any of themethods described herein.

Some embodiments include a non-transitory computer readable storagemedium, storing one or more programs configured for execution by one ormore processors of a storage device, the storage device includingnon-volatile memory, the one or more programs including instructions forperforming any operations of method 800 described above.

FIGS. 9A-9D illustrate a flowchart representation of a method 900 ofoperating a storage device that includes non-volatile memory, inaccordance with some embodiments. At least in some embodiments, method900 is performed by a storage device (e.g., storage device 120, FIG. 1)or one or more components of the storage device (e.g., storagecontroller 124, FIG. 1), wherein the storage device is operativelycoupled with a host system (e.g., computer system 110, FIG. 1). In someembodiments, method 900 is governed by instructions that are stored in anon-transitory computer readable storage medium and that are executed byone or more processors of a device, such as the one or more processingunits (CPUs) 122 of management module 121, shown in FIGS. 1 and 2. Insome embodiments, method 900 is performed by a storage system (e.g.,data storage system 100, FIG. 1) or one or more components of thestorage system (e.g., storage device 120, FIG. 1). In some embodiments,some of the operations of method 900 are performed at a storage device(e.g., storage device 120, FIG. 1) and information is transmitted to ahost (e.g., computer system 110, FIG. 1).

At a storage controller for the storage device (902), the storagecontroller including a first module (e.g., a front-end module, sometimesreferred to as the “Front End” or “FE”) and a second module (e.g., aback-end module, sometimes referred to as the “Flash Manager,” the“Flash Monitor,” and/or “FM”): the storage device (e.g., storage device120, FIG. 1) receives (906), at the second module, a garbage collectionread request from the first module, wherein the garbage collection readrequest specifies a source unit (e.g., a 96K source unit to garbagecollect, such as source block 402 and/or source block 408, FIG. 4A) anda tag to indicate the source unit contains last valid pages in a block.In some embodiments, a receiving module (e.g., receiving module 220,FIG. 2) is used to receive, at the second module, a garbage collectionread request from the first module, wherein the garbage collection readrequest specifies a source unit and a tag to indicate the source unitcontains last valid pages in a block, as described above with respect toFIG. 2. In some embodiments, garbage collection requests are produced bya module (e.g., Front End module 126, FIGS. 1 and 2, or other not shownmodule) that detects a trigger condition, such as the number of erasedblocks available for writing data falling below a threshold number, andthat upon detecting the trigger condition, identifies, in accordancewith predefined selection criteria (described above with reference toFIGS. 8A-8E), one or more blocks to be garbage collected.

In some embodiments, the storage device comprises (904) one or moreflash memory devices. In some embodiments, the storage device comprisesa storage medium (e.g., storage medium 130, FIG. 1), and the storagemedium comprises one or more non-volatile storage devices, such as flashmemory devices. In some embodiments, the storage medium (e.g., storagemedium 130, FIG. 1) is a single flash memory device, while in otherembodiments the storage medium includes a plurality of flash memorydevices. For example, in some embodiments, the storage medium includesdozens or hundreds of flash memory devices, organized in parallel memorychannels, such as 16, 32 or 64 flash memory devices per memory channel,and 8, 16 or 32 parallel memory channels. In some embodiments, thenon-volatile storage medium (e.g., storage medium 130, FIG. 1) includesNAND-type flash memory or NOR-type flash memory. In other embodiments,the storage medium comprises one or more other types of non-volatilestorage devices.

The storage device (e.g., storage device 120, FIG. 1), in response toreceiving the garbage collection read request, performs (908) one ormore operations for a garbage collection read, including: identifying(e.g., in accordance with a valid bitmap for the source unit) one ormore sequences of valid data in the source unit, wherein each identifiedsequence of valid data has a length selected from a set of predefinedlengths, the set including a first length (e.g., 4K), a second length(e.g., 8K), and a third length (e.g., 16K); for each respective sequenceof the one or more sequences of valid data in the source unit,transferring (e.g., reading and buffering) the respective sequence to arespective queue of a plurality of queues, in accordance with the lengthof the respective sequence (e.g., as described above with respect toFIG. 4A); and setting a global flag to flush all open respective queues(e.g., setting the global flag indicates that the next garbagecollection write request should flush all open respective queues,whether the queues are full or not full, as described above with respectto FIGS. 6A-6C).

In some embodiments, the valid bit map is specified by the garbagecollection read request, while in some other embodiments, the valid bitmap is obtained from a management data structure in accordance with thespecified source unit. In some embodiments, a garbage collection (GC)read module (e.g., GC read module 232, FIG. 2) is used to perform one ormore operations for a garbage collection read, including: identifyingone or more sequences of valid data in the source unit, wherein eachidentified sequence of valid data has a length selected from a set ofpredefined lengths, the set including a first length, a second length,and a third length; for each respective sequence of the one or moresequences of valid data in the source unit, transferring the respectivesequence to a respective queue of a plurality of queues, in accordancewith the length of the respective sequence; and setting a global flag toflush all open respective queues, as described above with respect toFIG. 2.

In some embodiments, each sequence of the one or more sequences of validdata in the source unit includes (916) one or more logical pages ofvalid data. In some embodiments, a logical page (sometimes referred toas an “L-page”) is the minimum granularity unit of data (e.g., 4K) fordata read commands or data read operations.

In some embodiments, identifying (e.g., in accordance with the validbitmap for the source unit) the one or more sequences of valid data inthe source unit includes (918): for each respective sequence of validdata, determining whether the respective sequence has the first length(e.g., 4K), the second length (e.g., 8K), or the third length (e.g.,16K) by: determining whether the respective sequence has the thirdlength; in accordance with a determination that the respective sequencedoes not have the third length, determining whether the respectivesequence has the second length; and in accordance with a determinationthat the respective sequence does not have the second length,determining whether the respective sequence has the first length. See,for example, FIG. 5 for patterns used to detect “runs” of valid data.

In some embodiments, transferring the respective sequence to therespective queue of the plurality of queues, in accordance with thelength of the respective sequence, includes (920): in accordance with adetermination that the respective sequence of valid data has the firstlength, transferring (e.g., reading and buffering) the respectivesequence of valid data into a first queue of a first type (e.g., a 4Kqueue extent that can hold four sequences of 4K length each, such as 4Kqueue 622, FIG. 6A); in accordance with a determination that therespective sequence of valid data has the second length, transferringthe respective sequence of valid data into a second queue of a secondtype (e.g., an 8K queue extent that can hold two sequences of 8K lengtheach, such as 8K queue 624, FIG. 6A); and in accordance with adetermination that the respective sequence of valid data has the thirdlength, transferring the respective sequence of valid data into a thirdqueue of a third type (e.g., a 16K queue extent that can hold onesequence of 16K length, such as 16K queue 626, FIG. 6A).

In some embodiments, the first queue, the second queue, and the thirdqueue are (922) the same size (e.g., 4 pages or 16K).

In some embodiments, in the plurality of queues, queues of the firsttype of queue each hold (924) single logical pages. For example, queuesof the first type of queue hold four sequences of 4K length each, eachsequence of 4K length sometimes referred to as a “4K run” (e.g., 4Kqueue 622, FIG. 6A).

In some embodiments, in the plurality of queues, queues of the secondtype of queue each hold (926) at least one sequence of logical pages ofat least the second length. For example, queues of the second type ofqueue hold two sequences of 8K length each, each sequence of 8K lengthsometimes referred to as an “8K run” (e.g., 8K queue 624, FIG. 6A).

In some embodiments, in the plurality of queues, queues of the thirdtype of queue each hold (928) at least one sequence of logical pages ofat least the third length. For example, queues of the third type ofqueue hold one sequence of 16K length, a sequence of 16K lengthsometimes referred to as a “16K run” (e.g., 16K queue 626, FIG. 6A).

In some embodiments, the storage device (e.g., storage device 120, FIG.1): in accordance with a determination that the first queue of the firsttype is full, allocates (930) a fourth queue of the first type; inaccordance with a determination that the second queue of the second typeis full, allocates a fifth queue of the second type; and in accordancewith a determination that the third queue of the third type is full,allocates a sixth queue of the third type. For example, in FIG. 6A, 16Kqueue 630 is allocated when 16K queue 626 is full, 8K queue 628 isallocated when 8K queue 624 is full, and a 4K queue (not shown) isallocated when 4K queue 622 is full. In some embodiments, an allocatingmodule (e.g., allocating module 236, FIG. 2) is used to allocate queues,as described above with respect to FIG. 2.

The storage device (e.g., storage device 120, FIG. 1) receives (910), atthe second module (e.g., Flash Manager 127, FIGS. 1 and 2), a garbagecollection write request from the first module (e.g., Front End 126,FIGS. 1 and 2). In some embodiments, a receiving module (e.g., receivingmodule 220, FIG. 2) is used to receive, at the second module, a garbagecollection write request from the first module, as described above withrespect to FIG. 2.

The storage device (e.g., storage device 120, FIG. 1), in response toreceiving the garbage collection write request and in accordance withthe global flag (e.g., in accordance with the global flag being set),performs (912) one or more operations for a garbage collection write,including: identifying open respective queues for writing to adestination unit, wherein open respective queues contain one or moresequences of valid data; and writing from the open respective queues tothe destination unit (e.g., as described above with respect to FIGS.6A-6C). In some embodiments, a garbage collection (GC) write module(e.g., GC write module 234, FIG. 2) is used to, in response to receivingthe garbage collection write request and in accordance with the globalflag, perform one or more operations for a garbage collection write,including: identifying open respective queues for writing to adestination unit, wherein open respective queues contain one or moresequences of valid data; and writing from the open respective queues tothe destination unit, as described above with respect to FIG. 2.

In some embodiments, writing from the open respective queues to thedestination unit includes (932) writing from the open respective queuesin sequence, from oldest open respective queue to newest open respectivequeue, to the destination unit (e.g., as described above with respect toFIG. 6A, where 4K queue 622 is the oldest open queue). In someembodiments, writing from the open respective queues to the destinationunit includes first writing to the destination unit the complete or fullqueues, from oldest to newest, and then writing to the destination unitany incomplete queues, from oldest to newest.

In some embodiments, at least one of the identified open respectivequeues is (934) not full (e.g., an open 4K queue extent that holds lessthan four sequences of 4K length each, such as 4K queue 622 in FIG. 6A,or an open 8K queue extent that holds less than two sequences of 8Klength each, such as 8K queue 628 in FIG. 6A).

In some embodiments, writing from the open respective queues to thedestination unit includes (936) (e.g., prior to writing data from theopen respective queues to the destination unit) combining openrespective queues that are not full to minimize unused space in thedestination unit. See, for example, FIGS. 6A-6C. It is noted that thecombining of open respective queues may change which queues are completeor full queues.

In some embodiments, the plurality of queues comprises (938) buffermemory distinct from non-volatile memory in the destination unit (e.g.,distinct from destination block 640, FIG. 6A).

In some embodiments, the storage device, after writing from the openrespective queues to the destination unit, marks (914) the block (e.g.,the block containing the last valid pages which were in an incompletequeue extent that was written) as eligible for erasing. In someembodiments, a marking module (e.g., marking module 240, FIG. 2) is usedto mark the block as eligible for erasing, as described above withrespect to FIG. 2.

In some embodiments, any operations of method 900 described above areperformed by a storage device, the storage device including (1)non-volatile memory (e.g., comprising one or more non-volatile storagedevices, such as flash memory devices), (2) a storage controller for thestorage device, the storage controller including a first module and asecond module (3) one or more processors, and (4) controller memory(e.g., non-volatile memory or volatile memory in or coupled to thecontroller) storing one or more programs, which when executed by the oneor more processors cause the storage device to perform or controlperformance of any of the methods described herein.

In some embodiments, any operations of method 900 described above areperformed by a storage device including means for performing any of themethods described herein.

In some embodiments, any operations of method 900 described above areperformed by a storage system comprising (1) a storage medium (e.g.,comprising one or more non-volatile storage devices, such as flashmemory devices) (2) one or more processors, and (3) memory (e.g.,non-volatile memory or volatile memory in the storage system) storingone or more programs, which when executed by the one or more processorscause the storage system to perform or control performance of any of themethods described herein.

Some embodiments include a non-transitory computer readable storagemedium, storing one or more programs configured for execution by one ormore processors of a storage device, the storage device includingnon-volatile memory, the one or more programs including instructions forperforming any operations of method 900 described above.

Furthermore, in some embodiments, one or more features of method 900 areused in implementations of method 800. Similarly, in some embodiments,one or more features of method 800 are used in implementations of method900.

Semiconductor memory devices include volatile memory devices, such asdynamic random access memory (“DRAM”) or static random access memory(“SRAM”) devices, non-volatile memory devices, such as resistive randomaccess memory (“ReRAM”), electrically erasable programmable read onlymemory (“EEPROM”), flash memory (which can also be considered a subsetof EEPROM), ferroelectric random access memory (“FRAM”), andmagnetoresistive random access memory (“MRAM”), and other semiconductorelements capable of storing information. Each type of memory device mayhave different configurations. For example, flash memory devices may beconfigured in a NAND or a NOR configuration.

The semiconductor memory elements located within and/or over a substratemay be arranged in two or three dimensions, such as a two dimensionalmemory structure or a three dimensional memory structure.

The term “three-dimensional memory device” (or 3D memory device) isherein defined to mean a memory device having multiple memory layers ormultiple levels (e.g., sometimes called multiple memory device levels)of memory elements, including any of the following: a memory devicehaving a monolithic or non-monolithic 3D memory array; or two or more 2Dand/or 3D memory devices, packaged together to form a stacked-chipmemory device.

One of skill in the art will recognize that this invention is notlimited to the two dimensional and three dimensional structuresdescribed but cover all relevant memory structures within the spirit andscope of the invention as described herein and as understood by one ofskill in the art.

It will be understood that, although the terms “first,” “second,” etc.may be used herein to describe various elements, these elements shouldnot be limited by these terms. These terms are only used to distinguishone element from another. For example, a first storage device could betermed a second storage device, and, similarly, a second storage devicecould be termed a first storage device, without changing the meaning ofthe description, so long as all occurrences of the “first storagedevice” are renamed consistently and all occurrences of the “secondstorage device” are renamed consistently. The first storage device andthe second storage device are both storage devices, but they are not thesame storage device.

The terminology used herein is for the purpose of describing particularembodiments only and is not intended to be limiting of the claims. Asused in the description of the embodiments and the appended claims, thesingular forms “a,” “an” and “the” are intended to include the pluralforms as well, unless the context clearly indicates otherwise. It willalso be understood that the term “and/or” as used herein refers to andencompasses any and all possible combinations of one or more of theassociated listed items. It will be further understood that the terms“comprises” and/or “comprising,” when used in this specification,specify the presence of stated features, integers, steps, operations,elements, and/or components, but do not preclude the presence oraddition of one or more other features, integers, steps, operations,elements, components, and/or groups thereof.

As used herein, the term “if” may be construed to mean “when” or “upon”or “in response to determining” or “in accordance with a determination”or “in response to detecting,” that a stated condition precedent istrue, depending on the context. Similarly, the phrase “if it isdetermined [that a stated condition precedent is true]” or “if [a statedcondition precedent is true]” or “when [a stated condition precedent istrue]” may be construed to mean “upon determining” or “in response todetermining” or “in accordance with a determination” or “upon detecting”or “in response to detecting” that the stated condition precedent istrue, depending on the context.

The foregoing description, for purpose of explanation, has beendescribed with reference to specific embodiments. However, theillustrative discussions above are not intended to be exhaustive or tolimit the claims to the precise forms disclosed. Many modifications andvariations are possible in view of the above teachings. The embodimentswere chosen and described in order to best explain principles ofoperation and practical applications, to thereby enable others skilledin the art.

What is claimed is:
 1. A method for operating a storage device thatincludes non-volatile memory, the method comprising: at a storagecontroller for the storage device: receiving a plurality of garbagecollection requests, wherein each garbage collection request specifies asource unit; in response to receiving a garbage collection request ofthe plurality of garbage collection requests, performing the followingoperations for a garbage collection read, including: identifying one ormore sequences of valid data in the source unit, wherein each identifiedsequence of valid data has a length of one of a plurality of predefinedlengths, the plurality of predefined lengths including at least a firstlength, a second length, and a third length, wherein the first length,second length and third length are separate and distinct from eachother; and for each respective sequence of the one or more sequences ofvalid data in the source unit, transferring the respective sequence to arespective queue of a plurality of queues, in accordance with the lengthof the respective sequence; and after performing the operations for thegarbage collection read, performing the following operations for agarbage collection write, including: identifying full respective queuesfor writing to a destination unit; and writing from the full respectivequeues to the destination unit.
 2. The method of claim 1, wherein theplurality of queues comprises buffer memory distinct from non-volatilememory in the destination unit.
 3. The method of claim 1, wherein: thestorage controller for the storage device includes a first module and asecond module; receiving the plurality of garbage collection requestsincludes receiving, at the second module, a plurality of garbagecollection read requests from the first module; and the operations forthe garbage collection read are performed in response to receiving arespective garbage collection read request of the plurality of garbagecollection read requests.
 4. The method of claim 3, including: prior toperforming the operations for the garbage collection write, receiving,at the second module, a garbage collection write request from the firstmodule; and performing the operations for the garbage collection writein response to receiving the garbage collection write request.
 5. Themethod of claim 1, wherein each sequence of the one or more sequences ofvalid data in the source unit includes one or more logical pages ofvalid data.
 6. The method of claim 1, wherein identifying the one ormore sequences of valid data in the source unit includes: for eachrespective sequence of valid data, determining whether the respectivesequence has the first length, the second length, or the third lengthby: determining whether the respective sequence has the third length; inaccordance with a determination that the respective sequence does nothave the third length, determining whether the respective sequence hasthe second length; and in accordance with a determination that therespective sequence does not have the second length, determining thatthe respective sequence has the first length.
 7. The method of claim 1,wherein transferring the respective sequence to the respective queue ofthe plurality of queues, in accordance with the length of the respectivesequence, includes: in accordance with a determination that therespective sequence of valid data has the first length, transferring therespective sequence of valid data into a first queue of a first type; inaccordance with a determination that the respective sequence of validdata has the second length, transferring the respective sequence ofvalid data into a second queue of a second type; and in accordance witha determination that the respective sequence of valid data has the thirdlength, transferring the respective sequence of valid data into a thirdqueue of a third type, wherein the first type, the second type and thethird type are separate and distinct from each other.
 8. The method ofclaim 7, wherein the first queue, the second queue, and the third queueare the same size.
 9. The method of claim 7, wherein, in the pluralityof queues, queues of the first type of queue each hold single logicalpages.
 10. The method of claim 7, wherein, in the plurality of queues,queues of the second type of queue each hold at least one sequence oflogical pages of at least the second length.
 11. The method of claim 7,wherein, in the plurality of queues, queues of the third type of queueeach hold at least one sequence of logical pages of at least the thirdlength.
 12. The method of claim 7, including: in accordance with adetermination that the first queue of the first type is full, allocatinga fourth queue of the first type; in accordance with a determinationthat the second queue of the second type is full, allocating a fifthqueue of the second type; and in accordance with a determination thatthe third queue of the third type is full, allocating a sixth queue ofthe third type.
 13. The method of claim 1, wherein writing from the fullrespective queues to the destination unit includes writing from the fullrespective queues in sequence, from an oldest full respective queue to anewest full respective queue, to the destination unit.
 14. The method ofclaim 1, wherein writing from the full respective queues to thedestination unit includes writing from the full respective queues to thedestination unit until the destination unit is full.
 15. The method ofclaim 1, including: prior to performing the operations for the garbagecollection write: in accordance with logical address information,rearranging one or more sequences of valid data in the plurality ofqueues to group logically sequential data together, wherein at least onequeue in the plurality of queues has a longer sequence of logicallysequential data after the rearranging than before the rearranging. 16.The method of claim 1, wherein identifying full respective queues andwriting from the full respective queues includes: identifying fullrespective queues for writing to one or more destination units in one ormore memory channels, respectively; and in accordance with adetermination that at least N of the full respective queues arelogically sequential, where N is a predefined integer greater than one,writing the N full respective queues that are logically sequential todestination units in at least two different memory channels.
 17. Themethod of claim 16, wherein writing the N full respective queues thatare logically sequential to destination units in at least two differentmemory channels includes: writing from a first queue of the N fullrespective queues that are logically sequential to a first destinationunit of a first memory channel; and writing from a second queue of the Nfull respective queues that are logically sequential to a seconddestination unit of a second memory channel.
 18. The method of claim 1,wherein the storage device comprises one or more flash memory devices.19. A storage device, comprising: non-volatile memory; means forreceiving a plurality of garbage collection requests, wherein eachgarbage collection request specifies a source unit; means for, inresponse to receiving a garbage collection request of the plurality ofgarbage collection requests, performing the following operations for agarbage collection read, using: means for identifying one or moresequences of valid data in the source unit, wherein each identifiedsequence of valid data has a length of one of a plurality of predefinedlengths, the plurality of predefined lengths including at least a firstlength, a second length, and a third length, wherein the first length,second length and third length are separate and distinct from eachother; and means for, for each respective sequence of the one or moresequences of valid data in the source unit, transferring the respectivesequence to a respective queue of a plurality of queues, in accordancewith the length of the respective sequence; and means for, afterperforming the operations for the garbage collection read, performingthe following operations for a garbage collection write, using: meansfor identifying full respective queues for writing to a destinationunit; and means for writing from the full respective queues to thedestination unit.
 20. A non-transitory computer readable storage medium,storing one or more programs configured for execution by one or moreprocessors of a storage device, the storage device includingnon-volatile memory, the one or more programs including instructions forperforming a set of operations, including: receiving a plurality ofgarbage collection requests, wherein each garbage collection requestspecifies a source unit; in response to receiving a garbage collectionrequest of the plurality of garbage collection requests, performing thefollowing operations for a garbage collection read, including:identifying one or more sequences of valid data in the source unit,wherein each identified sequence of valid data has a length of one of aplurality of predefined lengths, the plurality of predefined lengthsincluding at least a first length, a second length, and a third length,wherein the first length, second length and third length are separateand distinct from each other; and for each respective sequence of theone or more sequences of valid data in the source unit, transferring therespective sequence to a respective queue of a plurality of queues, inaccordance with the length of the respective sequence; and afterperforming the operations for the garbage collection read, performingthe following operations for a garbage collection write, including:identifying full respective queues for writing to a destination unit;and writing from the full respective queues to the destination unit.